/**
 * gvSIG. Desktop Geographic Information System.
 *
 * Copyright (C) 2007-2012 gvSIG Association.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA  02110-1301, USA.
 *
 * For any additional information, do not hesitate to contact us
 * at info AT gvsig.com, or visit our website www.gvsig.com.
 */
package org.gvsig.titleblock.main;

import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
import org.gvsig.fmap.mapcontrol.MapControl;
import org.gvsig.fmap.mapcontrol.MapControlCreationException;
import org.gvsig.fmap.mapcontrol.MapControlLocator;
import org.gvsig.fmap.mapcontrol.MapControlManager;
import org.gvsig.titleblock.ITBLocator;
import org.gvsig.titleblock.ITBManager;
import org.gvsig.titleblock.impl.TBToFFrame;
import org.gvsig.titleblock.swing.ITBSwingManager;
import org.gvsig.titleblock.swing.impl.JOpenTBPanel;
import org.gvsig.titleblock.swing.impl.TBSwingManager;
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
import org.gvsig.tools.locator.LocatorException;
import org.gvsig.tools.swing.api.ToolsSwingLocator;
import org.gvsig.tools.swing.api.windowmanager.WindowManager;

/**
 * Main executable class for testing the TitleBlock library.
 * 
 * @author gvSIG Team
 * @version $Id$
 */
public class Main {

    private ITBManager manager;

    private MapControlManager mapControlManager;

    private MapControl mapControl;

    public static void main(String args[]) throws MapControlCreationException, LocatorException, LoadLayerException {
        new DefaultLibrariesInitializer().fullInitialize(true);
    	Main main = new Main();
         main.show();
    }

    public void show() throws MapControlCreationException, LocatorException, LoadLayerException {
    	mapControlManager = MapControlLocator.getMapControlManager();
        manager = ITBLocator.getManager();

//        LayoutPanel layout = new DefaultLayoutPanel();
        TBToFFrame tbToFFrame = new TBToFFrame(manager);
	    manager.initialize(null, tbToFFrame, null);
    	
	    ITBSwingManager swingManager = new TBSwingManager();
	    JOpenTBPanel panel = (JOpenTBPanel)swingManager.createJOpenTBPanel(manager);
	   
	    //No se engancharlo bien :S
	    /*TBToFFrame btf=new TBToFFrames(layout);
		panel.setBoxToFrames(btf);
		panel.setLayout(layout);*/
	    
	    ToolsSwingLocator.getWindowManager().showWindow(panel, "Panel para abrir", WindowManager.MODE.WINDOW);
	    
	}
    
        
//    public class PropertiesOfBlockListener extends AbstractPointListener {
//    	
//    	public void point(PointEvent event) throws BehaviorException {
//    		TitleBlockSwingManager swingManager = TitleBlockSwingLocator.getSwingManager();
//
//    		TitleBlockBlock block;
//    		try {
//    			block = swingManager.getManager().getBlock(event.getMapPoint());
//    			if( block == null ) {
//    				return;
//    			}
//    			JPanel panel = swingManager.createJTitleBlockBlockPanel(block);
//    			ToolsSwingLocator.getWindowManager().showWindow(panel, "Block information", WindowManager.MODE.TOOL);
//    		} catch (TBException e) {
//    			// FIXME: Process exception
//    			throw new RuntimeException("Can't show properties of selected block.",e);
//    		}
//    	}
//
//    }

}


